#ifndef _PROTO_SERVERMANAGER_H_
#define _PROTO_SERVERMANAGER_H_

#include "app/app.h"
#include "net/net.h"
#include "pack/pack.h"
#include "common/common.h"

namespace proto {

/* Server -> ServerManager */
/* 每1个Server在开始的时候，都会向ServerManager服务器发送该请求 */
class PRegisterServer : public pack::IPacket {
public:
    enum { URI = 1 };

public:
    uint32_t server_type; 

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

class RRegisterServer : public pack::IPacket {
public:
    enum { URI = 2 };

public:
    uint32_t is_success;

    uint32_t ip;
    uint32_t port; 
    uint32_t server_id; 

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

/* 当ServerManager挂了，需要恢复Server的状态 */
class PRecoverServer {

};

class RRecoverServer {

};

class PWatcherServer : public pack::IPacket {
public:
    typedef std::list<uint32_t> WATCHER_LIST;

public:
    enum { URI = 1 };

public:
    WATCHER_LIST watcher_list;

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

class RWatcherServer : public pack::IPacket {
public:
    typedef std::list<app::ServerInfo> SERVER_LIST;

public:
    enum { URI = 1 };

public:
    SERVER_LIST server_list;

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

class PServerAdd : public pack::IPacket {
public:
    enum { URI = 1 };

public:
    app::ServerInfo server_info;

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

class PServerRemove: public pack::IPacket {
public:
    enum { URI = 1 };

public:
    app::ServerInfo server_info;

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

/* 查询1台Server的信息(需要Server的IP和Port） */
class PQueryServer : public pack::IPacket {
public:
    enum { URI = 1 };

public:
    uint32_t ip;
    uint32_t port;

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

/* ServerManager返回的Server信息:
 * A.is_server表示该Server是否是1台合法(已经向ServerManager注册)的
*/
class RQueryServer : public pack::IPacket {
public:
    enum { URI = 1 };

public:
    bool is_server;

    app::ServerInfo server_info;

public:	
    virtual uint32_t GetUri();

    virtual bool Pack(pack::Writer& writer);
    virtual bool UnPack(pack::Reader& reader);

    virtual std::string Dump();
};

class PStartServer : public pack::IPacket {
	public:
		enum { URI = 1 };

	public:
		app::ServerInfo server_info;

	public:	
		virtual uint32_t GetUri();

		virtual bool Pack(pack::Writer& writer);
		virtual bool UnPack(pack::Reader& reader);
};

class RStartServer {

};

class PStopServer : public pack::IPacket {
	public:
		enum { URI = 1 };

	public:
		app::ServerInfo server_info;

	public:	
		virtual uint32_t GetUri();

		virtual bool Pack(pack::Writer& writer);
		virtual bool UnPack(pack::Reader& reader);
};

class RStopServer {

};

class PPingServer : public pack::IPacket {
	public:
		enum { URI = 1 };

	public:
		app::ServerInfo server_info;

	public:	
		virtual uint32_t GetUri();

		virtual bool Pack(pack::Writer& writer);
		virtual bool UnPack(pack::Reader& reader);
};

}

#endif
